home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH6 / SRC / SPIRAL.FRM < prev    next >
Text File  |  1996-03-28  |  4KB  |  147 lines

  1. VERSION 4.00
  2. Begin VB.Form SpiralForm 
  3.    Caption         =   "Spiral"
  4.    ClientHeight    =   5310
  5.    ClientLeft      =   2115
  6.    ClientTop       =   1095
  7.    ClientWidth     =   4830
  8.    Height          =   6000
  9.    Left            =   2055
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   354
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   322
  14.    Top             =   465
  15.    Width           =   4950
  16.    Begin VB.TextBox DtText 
  17.       Height          =   285
  18.       Left            =   2160
  19.       TabIndex        =   6
  20.       Text            =   "0.1"
  21.       Top             =   45
  22.       Width           =   615
  23.    End
  24.    Begin VB.TextBox TminText 
  25.       Height          =   285
  26.       Left            =   0
  27.       TabIndex        =   4
  28.       Text            =   "0"
  29.       Top             =   45
  30.       Width           =   615
  31.    End
  32.    Begin VB.CommandButton CmdGo 
  33.       Caption         =   "Go"
  34.       Default         =   -1  'True
  35.       Height          =   375
  36.       Left            =   4200
  37.       TabIndex        =   3
  38.       Top             =   0
  39.       Width           =   615
  40.    End
  41.    Begin VB.TextBox TmaxText 
  42.       Height          =   285
  43.       Left            =   1200
  44.       TabIndex        =   2
  45.       Text            =   "18.85"
  46.       Top             =   45
  47.       Width           =   615
  48.    End
  49.    Begin VB.PictureBox Canvas 
  50.       AutoRedraw      =   -1  'True
  51.       Height          =   4815
  52.       Left            =   0
  53.       ScaleHeight     =   -2.2
  54.       ScaleLeft       =   -1.1
  55.       ScaleMode       =   0  'User
  56.       ScaleTop        =   1.1
  57.       ScaleWidth      =   2.2
  58.       TabIndex        =   0
  59.       Top             =   480
  60.       Width           =   4815
  61.    End
  62.    Begin VB.Label Label1 
  63.       Caption         =   "dt"
  64.       Height          =   255
  65.       Index           =   1
  66.       Left            =   1920
  67.       TabIndex        =   5
  68.       Top             =   60
  69.       Width           =   255
  70.    End
  71.    Begin VB.Label Label1 
  72.       Caption         =   "<= t <="
  73.       Height          =   255
  74.       Index           =   0
  75.       Left            =   645
  76.       TabIndex        =   1
  77.       Top             =   60
  78.       Width           =   495
  79.    End
  80.    Begin VB.Menu mnuFile 
  81.       Caption         =   "&File"
  82.       Begin VB.Menu mnuFileExit 
  83.          Caption         =   "E&xit"
  84.       End
  85.    End
  86. End
  87. Attribute VB_Name = "SpiralForm"
  88. Attribute VB_Creatable = False
  89. Attribute VB_Exposed = False
  90. Option Explicit
  91.  
  92. Const PI = 3.14159
  93.  
  94.  
  95. ' ************************************************
  96. ' Draw the curve on the indicated picture box.
  97. ' ************************************************
  98. Sub DrawCurve(pic As PictureBox, start_t As Single, stop_t As Single, dt As Single)
  99. Dim t As Single
  100.  
  101.     pic.Cls
  102.     pic.CurrentX = X(start_t)
  103.     pic.CurrentY = Y(start_t)
  104.     
  105.     t = start_t + dt
  106.     Do While t < stop_t
  107.         pic.Line -(X(t), Y(t))
  108.         t = t + dt
  109.     Loop
  110.     
  111.     pic.Line -(X(stop_t), Y(stop_t))
  112. End Sub
  113.  
  114.  
  115.  
  116. ' ************************************************
  117. ' The parametric function Y(t).
  118. ' ************************************************
  119. Function Y(t As Single) As Single
  120.     Y = t * t / 350 * Sin(t)
  121. End Function
  122.  
  123. ' ************************************************
  124. ' The parametric function X(t).
  125. ' ************************************************
  126. Function X(t As Single) As Single
  127.     X = t * t / 350 * Cos(t)
  128. End Function
  129.  
  130. Private Sub CmdGo_Click()
  131. Dim tmin As Single
  132. Dim tmax As Single
  133. Dim dt As Single
  134.  
  135.     tmin = CSng(TminText.Text)
  136.     tmax = CSng(TmaxText.Text)
  137.     dt = CSng(DtText.Text)
  138.     DrawCurve Canvas, tmin, tmax, dt
  139. End Sub
  140.  
  141.  
  142. Private Sub mnuFileExit_Click()
  143.     Unload Me
  144. End Sub
  145.  
  146.  
  147.